import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:surfaceim/common/values/values.dart';
import 'package:surfaceim/common/widgets/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:phone_form_field/phone_form_field.dart';

import '../controller.dart';

class GetCode extends GetView<SignUpController> {
  @override
  Widget build(BuildContext context) {
    // print('TODO :  此处有大量重建 ; 应优化');

    return Container(
      margin: EdgeInsets.only(top: 49.h),
      child: Column(
        children: [
          Padding(
            padding: EdgeInsets.only(top: 74.h, right: 68.h, left: 68.h),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                primaryTitle(title: '请输入您的手机号码'),
                Padding(
                  padding: EdgeInsets.only(top: 55.h),
                  child: PhoneFormField(
                    onChanged: (PhoneNumber? p) {
                      controller.mobileController = p!;
                    },
                    // controller: controller.mobileController,
                    cursorColor: AppColors.primaryElementSecondary,
                    defaultCountry: 'CN', // default
                    decoration: InputDecoration(
                      // labelText: '手机号码',
                      labelStyle:
                          TextStyle(color: AppColors.primaryElementSecondary),
                      focusColor: AppColors.primaryElementSecondary,
                      focusedBorder: UnderlineInputBorder(
                          borderSide: BorderSide(
                        color: AppColors.primaryElementSecondary,
                        width: 1, //宽度为5
                      )),
                    ),
                    validator: PhoneValidator.none, // 空验证
                    selectorNavigator: BottomSheetNavigator(
                      favorites: [
                        'CN',
                        'US',
                        'GB',
                        'RU',
                        'FR',
                        'IT',
                        'DE',
                        'IN',
                        'JP',
                        'KR',
                      ], // 常用国家列表
                    ),
                    // showFlagInInput: true, // default
                    flagSize: 32.sp, // default
                    autofillHints: [
                      AutofillHints.telephoneNumber
                    ], // default to null
                    enabled: true, // default
                    autofocus: false, // 自动获取焦点
                    autovalidateMode:
                        AutovalidateMode.onUserInteraction, // 自动验证
                  ),
                ),
                Padding(
                  padding: EdgeInsets.only(top: 55.h),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      GetBuilder<SignUpController>(
                          id: 'Agreement',
                          init: controller,
                          initState: (_) {},
                          builder: (_) {
                            return MediaQuery.removePadding(
                              removeTop: true,
                              removeLeft: true,
                              removeRight: true,
                              removeBottom: true,
                              context: context,
                              child: Checkbox(
                                materialTapTargetSize:
                                    MaterialTapTargetSize.shrinkWrap,
                                value: controller.isRead,
                                // 选中后的颜色
                                activeColor: AppColors.secondaryElementText,
                                // 选中后对号的颜色
                                checkColor: AppColors.primaryElementText,
                                onChanged: (bool? value) {
                                  controller.userAgreement(value);
                                },
                              ),
                            );
                          }),
                      RichText(
                        text: TextSpan(children: [
                          TextSpan(
                              text: '我已阅读 ',
                              style: TextStyleTertiary(
                                  color: AppColors.thirdElementText),
                              recognizer: TapGestureRecognizer()
                                ..onTap = () {
                                  controller.userAgreement(!controller.isRead);
                                }),
                          TextSpan(
                              text: '《用户协议》',
                              style: TextStyleTertiary(
                                  color: AppColors.secondaryElementText),
                              recognizer: TapGestureRecognizer()
                                ..onTap = () {
                                  // 查看用户协议
                                  Get.toNamed('/user_agreement');
                                }),
                          TextSpan(
                            text: ' 和 ',
                            style: TextStyleTertiary(
                                color: AppColors.thirdElementText),
                          ),
                          TextSpan(
                              text: '《个人信息保护》',
                              style: TextStyleTertiary(
                                  color: AppColors.secondaryElementText),
                              recognizer: TapGestureRecognizer()
                                ..onTap = () {
                                  Get.toNamed('/terms_of_service');
                                  // 查看 服务条款
                                }),
                        ]),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Padding(
            padding: EdgeInsets.only(top: 108.h),
            child: primaryButtonWidget(
              width: 370,
              title: '下一步',
              onPressed: controller.handleSignUp,
            ),
          ),
        ],
      ),
    );
  }
}
